<template>
  <basic-container>
    <el-tabs type="border-card" class="informationLabel">
      <el-tab-pane label="标签置换及打印">
        <el-row :gutter="20">
          <el-col :span="11">
            <avue-form
              id="rawMaterialOtherForm"
              class="newFormStyle"
              key="2"
              ref="rawMaterialOtherForm"
              v-model="rawMaterialOtherForm"
              :option="rawMaterialOtherOption"
              @submit="rawMaterialOtherLabelGenerate"
            >
              <template slot-scope="{}" slot="mpqLabel">
                <el-tooltip class="item" effect="dark" content="MPQ（Minimum Package Quantity）指物料最小包装数量" placement="top-start">
                  <i class="el-icon-info"></i>
                </el-tooltip>
                <span>&nbsp;MPQ:</span>
              </template>
            </avue-form>
          </el-col>
          <el-col :span="12">
            <div class="sequenceInfo">
              <table border="1">
                <tr>
                  <th colspan="4">产品序列号规则说明</th>
                </tr>
                <tr>
                  <th>规则名称</th>
                  <th>
                    <el-tooltip class="item" effect="dark" placement="top-start">
                      <i class="el-icon-info" style="color: #606266"></i>
                      <div slot="content">
                        [P]：前缀字符,[YY]：两位年份, [YYYY]：四位年份, [M]：月,<br />[W]：周, [D]：日, [S]：流水号, [N]：自定义字符。<br />[B]：后缀字符 <br />如：[YY][M][S][B]
                        <br />若无流水号则没有[S],例如：[YY][M][B]
                      </div>
                      <!-- <el-button style="padding: 0; font-size: 18px" type="info" icon="el-icon-info" circle></el-button> -->
                    </el-tooltip>
                    序列号规则
                    <el-button
                      v-if="
                        sequenceRuleInfo.sequenceNoFormat &&
                        (sequenceRuleInfo.sequenceNoFormat.indexOf('[YYYY]') > -1 ||
                          sequenceRuleInfo.sequenceNoFormat.indexOf('[YY]') > -1 ||
                          sequenceRuleInfo.sequenceNoFormat.indexOf('[M]') > -1 ||
                          sequenceRuleInfo.sequenceNoFormat.indexOf('[W]') > -1 ||
                          sequenceRuleInfo.sequenceNoFormat.indexOf('[D]') > -1)
                      "
                      style="padding: 5px"
                      type="primary"
                      icon="el-icon-edit"
                      circle
                    ></el-button>
                  </th>
                  <th>序列号规则位数</th>
                  <th>当前流水号</th>
                </tr>
                <tr style="height: 40px">
                  <td>{{ sequenceRuleInfo.name }}</td>
                  <td>
                    <div>{{ sequenceRuleInfo.sequenceNoFormat }}</div>
                    <div>{{ sequenceRuleInfo.sequenceNoFormatZh }}</div>
                  </td>
                  <td>
                    <div v-if="sequenceRuleInfo.charactersCount">配置长度:{{ sequenceRuleInfo.charactersCount }}</div>
                    <div v-if="sequenceRuleInfo.seqNoFormatDemo">
                      例:{{ sequenceRuleInfo.seqNoFormatDemo }}<span>(当前长度:{{ sequenceRuleInfo.seqNoFormatDemo.length }})</span>
                    </div>
                  </td>
                  <td>{{ sequenceRuleInfo.sequenceNo }}</td>
                </tr>
              </table>
              <table class="generateSerialNoInfo" border="1">
                <tr>
                  <th colspan="4">产品序列号规则生成示例</th>
                </tr>
                <tr>
                  <th>序列号规则</th>
                  <th>序列号数量</th>
                  <th>起始序列号</th>
                  <th>结尾序列号</th>
                </tr>
                <tr style="height: 40px">
                  <td>[YY][M][S]两位年份[YY]+两位月码[M]+流水[S]</td>
                  <td>10</td>
                  <td>220400001</td>
                  <td>220400010</td>
                </tr>
              </table>
              <el-row>
                <el-col :span="15">
                  <common-printers-template ref="printInfo" templateType="MATERIAL" @getPrintInfo="getPrintInfo"></common-printers-template>
                </el-col>
                <el-col :span="15" class="btn-group">
                  <el-button type="primary" size="small" @click="$refs.rawMaterialOtherForm.submit()">置换标签</el-button>
                  <el-button type="primary" size="small" @click="handlePrintTest">打印测试</el-button>
                  <el-button type="primary" size="small" @click="batchPrinting">打印标签</el-button>
                </el-col>
              </el-row>
            </div>
          </el-col>
        </el-row>
      </el-tab-pane>
    </el-tabs>

    <el-tabs type="border-card" class="informationLabel mt8">
      <el-tab-pane label="标签记录">
        <avue-crud
          :defaults.sync="recordDefaults"
          class="serialNoGenerationRecord"
          ref="serialNoGenerationRecord"
          :table-loading="loading"
          :option="serialNoGenerationRecordOption"
          :data="serialnoData"
          @row-click="serialnoRowClick"
        >
          <template slot-scope="{ row }" slot="menu">
            <div class="menu-option">
              <el-button icon="el-icon-printer" size="small" type="text" @click="rowPrint(row)"> 重打 </el-button>
            </div>
          </template>
        </avue-crud>
      </el-tab-pane>
    </el-tabs>

    <!-- 操作日志 -->
    <operation-log ref="operationLog"></operation-log>
    <!--重打弹窗-->
    <!--    <el-dialog append-to-body title="重打" v-if="printInfoModel" :visible.sync="printInfoModel" width="35%">-->
    <!--      <div style="display: flex; justify-content: center; margin-bottom: 10px">-->
    <!--        <span style="color: red">注：仅需修改流水号即可，重打的起始流水号和结束流水号需在原流水号范围内</span>-->
    <!--      </div>-->
    <!--      <avue-form ref="printForm" v-model="repeatPrintInfo" :option="printInfoOption"> </avue-form>-->
    <!--      <span slot="footer" class="dialog-footer">-->
    <!--        <el-button size="small" type="primary" @click="printSubmit"><i class="el-icon-printer"></i><span>重打</span></el-button>-->
    <!--        <el-button size="small" @click="printInfoModel = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>-->
    <!--      </span>-->
    <!--    </el-dialog>-->
    <common-modal-template ref="commonModalTemplate" :option="tableOption" @getSelectedRows="getSelectedRows" :key="timer" @newKey="newKey"></common-modal-template>
  </basic-container>
</template>

<script>
import { getOption } from './barcodeDisplace';
import { showFailLog, showSuccessLog } from '@/util/helpers';
import { getSourceList, printSequence, sequenceCreateByPart } from '@/api/warehouse/warehouse-label-create-print';
import CommonModalTemplate from '@/components/common-modal-template/common-modal-template.vue';
import CommonPrintersTemplate from '@/components/common-printers-template/common-printers-template';
import OperationLog from '@/components/operation-log/operation-log';
import { getDetail as getSequencedefinitionDetail } from '@/api/admin/sequencedefinition';
import { getSeqNoRules } from '@/util/global';
import { packPrint } from '@/api/admin/barcode-record';

export default {
  name: 'barcodeGeneration',
  components: {
    CommonModalTemplate,
    CommonPrintersTemplate,
    OperationLog
  },
  data() {
    return {
      rawMaterialOtherForm: {}, //序列号生成信息,
      tableOption: {},
      timer: new Date().getTime(),
      loading: false,
      recordDefaults: {},
      serialNoGenerationRecordOption: {
        //工单产品序列号内容配置
        height: 300,
        calcHeight: 30,
        border: true,
        index: true,
        indexLabel: '序号',
        viewBtn: false,
        selection: false,
        dialogClickModal: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        tip: false,
        refreshBtn: false, //刷新按钮是否显示
        columnBtn: false, //控制表格列是否显示按钮是否显示
        menu: false,
        highlightCurrentRow: true,
        column: [
          {
            label: '起始包装条码',
            prop: 'sequenceNumberFrom'
          },
          {
            label: '结尾包装条码',
            prop: 'sequenceNumberTo'
          },
          {
            label: '包装条码数量',
            prop: 'quantity'
          },
          {
            label: '最小包装数量（MPQ）',
            prop: 'quantity'
          },
          {
            label: '生成时间',
            prop: 'createTime'
          },
          {
            label: '生成类型',
            prop: 'generationType',
            html: true,
            formatter: (val) => {
              switch (val.generationType) {
                case 'NORMAL':
                  return '正常';
                case 'SCRAP':
                  return '报废';
                case 'APPEND':
                  return '增补';
                case 'REPLACE':
                  return '置换';
                default:
                  break;
              }
            }
          },
          {
            label: '操作人',
            prop: 'quantity'
          },
          {
            label: '原因说明',
            prop: 'quantity'
          },
          {
            label: '状态',
            prop: 'isPrinted',
            html: true,
            formatter: (val) => {
              switch (val.isPrinted) {
                case 0:
                  return `<span class="text-yellow">未打印</span>`;
                case 1:
                  return `<span class="text-green">已打印</span>`;
                case 2:
                  return `<span class="text-red">部分打印</span>`;
                default:
                  return `<span class="text-red">报废</span>`;
                  break;
              }
            }
          }
        ]
      },
      serialnoData: [{}],
      printInfo: {}, //打印机打印模版信息
      sequenceRuleInfo: {}, //产品序列号规则信息
      printInfoModel: false,
      repeatPrintInfo: {},
      printInfoOption: {
        labelWidth: 150,
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '起始流水号',
            prop: 'startSequenceNumber',
            span: 20
          },
          {
            label: '结束流水号',
            prop: 'endSequenceNumber',
            span: 20
          },
          {
            label: '打印机',
            prop: 'equipmentName',
            span: 20,
            type: 'search',
            placeholder: '请选择 打印机',
            disabled: true,
            rules: [
              {
                required: true,
                message: '请选择打印机',
                trigger: 'blur'
              }
            ],
            appendClick: () => {
              this.openPrintersModal();
            }
          },
          {
            label: '标签模版',
            prop: 'labelTemplateName',
            span: 20,
            type: 'search',
            placeholder: '请选择 标签模板',
            disabled: true,
            rules: [
              {
                required: true,
                message: '请选择标签模板',
                trigger: 'blur'
              }
            ],
            appendClick: () => {
              this.openLabelTemplateModal();
            }
          }
        ]
      },
      rawMaterialOtherOption: getOption(this) //序列号生成信息配置内容
    };
  },
  methods: {
    rawMaterialOtherLabelGenerate(row, done) {
      if (!row.partNo) {
        this.$message({
          type: 'warning',
          message: '请选择物料!'
        });
        done();
        return;
      }
      if (!row.receiveQuantity) {
        this.$message({
          type: 'warning',
          message: '请选择收料数量!'
        });
        done();
        return;
      }
      if (!row.sequenceName) {
        this.$message({
          type: 'warning',
          message: '请选择序列号规则!'
        });
        done();
        return;
      }
      if (!row.mpq) {
        this.$message({
          type: 'warning',
          message: '请输入MPQ!'
        });
        done();
        return;
      }
      let reg1 = /^\d+(?:\.\d{0,3})?$/;
      if (!reg1.test(row.mpq)) {
        this.$message({
          type: 'warning',
          message: '小数点最多为3位'
        });
        done();
        return;
      }
      if (Number(row.mpq) > Number(row.receiveQuantity)) {
        this.$message({
          type: 'warning',
          message: 'MPQ不能大于收料数量！'
        });
        done();
        return;
      }
      if (!row.vendorDate) {
        this.$message({
          type: 'warning',
          message: '请选择生产日期!'
        });
        done();
        return;
      }
      // this.rawMaterialOtherForm['timeConfig'] = this.timeConfig;
      sequenceCreateByPart(this.rawMaterialOtherForm).then(
        (res) => {
          this.getSequenceRecordById(this.rawMaterialOtherForm.receivingId);
          this.$message({
            type: 'success',
            message: res.data.msg
          });
          showSuccessLog(res.data.msg);
          done();
        },
        (error) => {
          showFailLog(error.data.msg);
          done();
        }
      );
    },
    //打印测试
    handlePrintTest() {},
    /**
     * 标签打印
     */
    batchPrinting() {
      try {
        if (!this.printInfo.printersId) {
          this.$message({
            type: 'warning',
            message: '请选择打印机！'
          });
          return;
        }
        if (!this.printInfo.labelTemplateId) {
          this.$message({
            type: 'warning',
            message: '请选择标签模版！'
          });
          return;
        }
        let params = {
          equipmentId: this.printInfo.printersId,
          labelTemplateId: this.printInfo.labelTemplateId,
          receivingId: this.rawMaterialOtherForm.receivingId,
          sequenceGenerationId: this._get(this.selectionInfo, 'id', '')
        };
        printSequence(params).then(
          (res) => {
            this.$message({
              type: 'success',
              message: res.data.msg
            });
            showSuccessLog(res.data.msg);
            this.getSequenceRecordById(this.getRecordReceivingId);
          },
          (error) => {
            showFailLog(error.data.msg);
          }
        );
      } catch (e) {
        console.warn(e);
      }
    },
    // 重打
    rowPrint(row) {
      this.repeatPrintInfo.startSequenceNumber = row.sequenceNumberFrom;
      this.repeatPrintInfo.endSequenceNumber = row.sequenceNumberTo;
      this.repeatPrintInfo.generationId = row.id;
      this.printInfoModel = true;
    },
    printSubmit() {
      this.$refs.printForm.validate(async (valid, done) => {
        if (valid) {
          try {
            const params = {
              ...this.repeatPrintInfo,
              fromSequenceNumber: this.repeatPrintInfo.startSequenceNumber,
              toSequenceNumber: this.repeatPrintInfo.endSequenceNumber
            };
            delete params.startSequenceNumber;
            delete params.endSequenceNumber;
            const res = await packPrint(params);
            this.$refs.printForm.resetFields();
            this.printInfoModel = false;
            this.$message({
              type: 'success',
              message: '重打成功'
            });
          } catch (e) {
            console.warn(e);
          }
        }
      });
    },
    /**
     * 获取选择的模态框行数据
     */

    getSelectedRows(rowData) {
      switch (this.modalName) {
        case 'otherReceiveMoal':
          this.rawMaterialOtherForm.receiveRecord = '其他收料';
          this.partId = this._get(rowData, 'partMasterId', '');
          this.rawMaterialOtherForm.receivingId = this._get(rowData, 'id', '');
          this.rawMaterialOtherForm.partId = this._get(rowData, 'partMasterId', '');
          this.rawMaterialOtherForm.partNo = this._get(rowData, 'partNo', '');
          this.rawMaterialOtherForm.partName = this._get(rowData, 'partName', '');
          this.rawMaterialOtherForm.partModel = this._get(rowData, 'partModel', '');
          this.rawMaterialOtherForm.sequenceDefinitionId = this._get(rowData, 'packingSeqDefinitionId', '');
          this.rawMaterialOtherForm.sequenceName = this._get(rowData, 'packSeqDefinitionName', '');
          this.rawMaterialOtherForm.receiveQuantity = this._get(rowData, 'receiveQuantity', '');
          this.rawMaterialOtherForm.mpq = this._get(rowData, 'receivingOption.mpq', '');
          this.rawMaterialOtherForm.vendorDate = this._get(rowData, 'vendorDate', '');
          this.rawMaterialOtherForm.vendorLotNo = this._get(rowData, 'vendorLotNo', '');
          this.rawMaterialOtherForm.vendorCode = this._get(rowData, 'vendorCode', '');
          this.rawMaterialOtherForm.vendorName = this._get(rowData, 'vendorName', '');
          this.rawMaterialOtherForm.description = '';
          if (this.rawMaterialOtherForm.sequenceDefinitionId) {
            this.getSequencedefinitionDetail(this.rawMaterialOtherForm.sequenceDefinitionId);
          }
          this.getSequenceRecordById(this.rawMaterialOtherForm.receivingId);
          break;
        case 'serialnoModal':
          this.rawMaterialOtherForm.sequenceName = this._get(rowData, 'name', '');
          this.rawMaterialOtherForm.sequenceDefinitionId = this._get(rowData, 'id', '');
          break;
        case 'printersModal':
          this.repeatPrintInfo.equipmentId = this._get(rowData, 'id', '');
          this.repeatPrintInfo.equipmentName = this._get(rowData, 'name', '');
          break;
        case 'labelTemplateModal':
          this.repeatPrintInfo.labelTemplateId = this._get(rowData, 'id', '');
          this.repeatPrintInfo.labelTemplateName = this._get(rowData, 'fileName', '');
          break;
        default:
          break;
      }
    },
    /*
     * 根据序列号规则ID查询详情
     */
    getSequencedefinitionDetail(sequencedefinitionId) {
      getSequencedefinitionDetail(sequencedefinitionId).then((res) => {
        this.$set(this.sequenceRuleInfo, 'name', this._get(res, 'data.data.name', ''));
        this.$set(this.sequenceRuleInfo, 'sequenceNoFormat', this._get(res, 'data.data.sequenceNoFormat', ''));
        this.$set(this.sequenceRuleInfo, 'sequenceNoFormatZh', this._get(res, 'data.data.sequenceNoFormatZh', ''));
        this.$set(this.sequenceRuleInfo, 'seqNoFormatDemo', this._get(res, 'data.data.seqNoFormatDemo', ''));
        this.$set(this.sequenceRuleInfo, 'containsSequenceNo', this._get(res, 'data.data.containsSequenceNo', true));
        this.$set(this.sequenceRuleInfo, 'charactersCount', this._get(res, 'data.data.charactersCount', 0));
        this.seqNoConvert();
      });
    },
    serialnoRowClick(row) {
      this.selectionInfo = row;
      this.$refs.serialNoGenerationRecord.toggleSelection(row);
    },
    /*
     * 序列号规则转换中文
     * @param sequenceNoValue 序列号规则
     * @param sequenceNo 序列号规则起始流水号
     */
    seqNoConvert() {
      let seqNoRules = [];
      this._forEach(getSeqNoRules(), (item) => {
        seqNoRules = [...seqNoRules, ...item.value];
      });
      let splitList = this.sequenceRuleInfo.sequenceNoFormat.split('');
      //在[前加空格  ]后加空格
      splitList = splitList.map((item) => {
        if (item === '[') {
          return ' [';
        } else if (item === ']') {
          return '] ';
        } else {
          return item;
        }
      });
      splitList = splitList.join('');
      //按空格拆分字符串
      splitList = splitList.split(' ');
      //匹配中文
      let splitArr = this._map(splitList, (item) => {
        this._forEach(seqNoRules, (ele) => {
          if (item === ele.key) {
            item = ele.value;
          }
        });
        return item;
      });
      //去除空格
      splitArr = splitArr.filter(function (s) {
        return s && s.trim();
      });
      //转换后给序列号规则赋值
      this.sequenceRuleInfo.sequenceNoFormatZh = splitArr.join('+');

      let splitDemoArr = this._map(splitList, (item) => {
        this._forEach(seqNoRules, (ele) => {
          if (item === ele.key) {
            let currentDate = new Date();
            switch (item) {
              case '[YY]':
                let year = String(currentDate.getFullYear());
                item = year.substring(2, year.length);
                break;
              case '[YYYY]':
                item = currentDate.getFullYear();
                break;
              case '[M]':
                let month = currentDate.getMonth() + 1;
                if (month < 10) {
                  item = '0' + month;
                } else {
                  item = month;
                }
                break;
              case '[W]':
                let today = new Date();
                let firstDay = new Date(today.getFullYear(), 0, 1);
                let dayOfWeek = firstDay.getDay();
                let spendDay = 1;
                if (dayOfWeek != 0) {
                  spendDay = 7 - dayOfWeek + 1;
                }
                firstDay = new Date(today.getFullYear(), 0, 1 + spendDay);
                let d = Math.ceil((today.valueOf() - firstDay.valueOf()) / 86400000);
                let week = Math.ceil(d / 7);
                week = week + 1;
                if (week < 10) {
                  item = '0' + week;
                } else {
                  item = week;
                }
                break;
              case '[D]':
                let day = currentDate.getDate();
                if (day < 10) {
                  item = '0' + day;
                } else {
                  item = day;
                }
                break;
              case '[S]':
                if (this.sequenceRuleInfo.sequenceNo) {
                  item = this.sequenceRuleInfo.sequenceNo;
                } else {
                  item = this.sequenceRuleInfo[ele.code];
                }
                break;
              case '[WO]':
                if (this.model.workOrderNo) {
                  item = this.model.workOrderNo;
                } else {
                  item = '[WO]';
                }
                break;
              default:
                if (ele.code) {
                  item = this.sequenceRuleInfo[ele.code];
                }
                break;
            }
          }
        });
        return item;
      });
      splitDemoArr = splitDemoArr.filter(function (item) {
        return String(item) && String(item).trim();
      });
      this.sequenceRuleInfo.seqNoFormatDemo = splitDemoArr.join('');
    },
    /**
     * 获取打印机和打印模版信息
     */
    getPrintInfo(printInfo) {
      if (printInfo.printersId) {
        this.printInfo.printersId = printInfo.printersId;
      }
      if (printInfo.labelTemplateId) {
        this.printInfo.labelTemplateId = printInfo.labelTemplateId;
      }
    },
    openCommonModal(type) {
      // sheetNoModal / otherReceiveMoal
      this.modalName = type;
      this.$refs.commonModalTemplate.showModal();
      let url;
      if (type === 'otherReceiveMoal') {
        url = `/api/mes-warehouse/receiving/page?sequenceGenerated=false&receivingNotPrint=true&receiveType=OTHER`;
      }
      this.tableOption = {
        modalTitle: `请选择收料记录（双击进行选择）`,
        url,
        isPage: true,
        rowSelectionType: 'single',
        searchLabelWidth: 120,
        columnDefs: [
          {
            label: '单据号',
            prop: 'sheetNo',
            search: true
          },
          {
            label: '供应商编码',
            prop: 'vendorCode',
            search: true
          },
          {
            label: '供应商名称',
            prop: 'vendorName'
          },
          // {
          //   label: '供应商批次',
          //   prop: 'vendorLotNo'
          // },
          // {
          //   label: '单行号',
          //   prop: 'sheetLot'
          // },
          {
            label: '物料编码',
            prop: 'partNo',
            search: true
          },
          {
            label: '物料名称',
            prop: 'partName'
          },
          {
            label: '物料规格',
            prop: 'partModel'
          },
          {
            label: '收料数量',
            prop: 'receiveQuantity'
          },
          {
            label: '实收数量',
            prop: 'actuallyReceive'
          },
          {
            label: '收料人',
            prop: 'receivingUserName'
          },
          {
            label: '收料时间',
            prop: 'createTime'
          },
          // {
          //   label: '是否检验',
          //   prop: 'isTest',
          //   type: 'select',
          //   dicData: [
          //     {
          //       label: '否',
          //       value: false
          //     },
          //     {
          //       label: '是',
          //       value: true
          //     }
          //   ]
          // },
          {
            label: '送检单号',
            prop: 'inspectionOrderNo'
          }
          // {
          //   label: '送检批号',
          //   prop: 'inspectionLotNo'
          // }
        ]
      };
    },

    /**
     * 打开序列号规则选择模态框
     */
    openSerialnoCommonModal() {
      this.modalName = 'serialnoModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择序列号规则（双击进行选择）',
        url: '/api/mes-admin/sequencedefinition/page?type=material&subType=raw_material_packaging',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '序列号规则名称',
            prop: 'name',
            search: true,
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '序列号规则编码',
            prop: 'code',
            search: true,
            searchLabelWidth: 150,
            searchSpan: 8
          },
          {
            label: '进制符',
            prop: 'hexString'
          },
          {
            label: '起始流水号',
            prop: 'startSequenceNo'
          },
          {
            label: '序列号规则',
            prop: 'sequenceNoFormat'
          }
        ]
      };
    },

    /**
     * 获取打印机
     */
    openPrintersModal() {
      this.modalName = 'printersModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择打印机（双击进行选择）',
        url: '/api/mes-product/ems-equipment/page?type=PRINTER',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '打印机编码',
            prop: 'code',
            search: true,
            searchLabelWidth: 110
          },
          {
            label: '打印机名称',
            prop: 'name',
            search: true,
            searchLabelWidth: 110
          }
        ]
      };
    },
    /**
     * 打开标签模板模态框
     */
    openLabelTemplateModal() {
      this.modalName = 'labelTemplateModal';
      this.$refs.commonModalTemplate.showModal();
      this.tableOption = {
        modalTitle: '选择标签模版（双击进行选择）',
        url: '/api/mes-admin/labeltemplate/page?status=1',
        isPage: true,
        rowSelectionType: 'single',
        columnDefs: [
          {
            label: '标签名称',
            prop: 'fileName',
            search: true
          },
          {
            label: '标签代码',
            prop: 'code',
            search: true
          },
          {
            label: '版本名称',
            prop: 'revision'
          },
          {
            label: '缩略图',
            prop: 'thumbnailUrl'
          },
          {
            label: '打印标签',
            prop: 'fileUrl'
          }
        ]
      };
    },
    newKey() {
      this.timer = new Date().getTime();
    },
    /**
     * 根据id获取所有生成记录
     */
    getSequenceRecordById(id) {
      let params = {
        sourceId: id
      };
      this.loading = true;
      getSourceList(params)
        .then(
          (res) => {
            this.serialnoData = this._get(res, 'data.data', []);
          },
          (error) => {
            this.serialnoData = [];
          }
        )
        .finally((this.loading = false));
    }
  }
};
</script>

<style scoped lang="scss">
.sequenceInfo {
  table {
    width: 100%;
    height: auto;
    margin-bottom: 10px;
    font-size: 14px;
    th {
      border: 1px solid #ebeef5;
      background: #fafafa;
      height: 30px;
    }
    tr {
      border: 1px solid #ebeef5;
    }
    td {
      border: 1px solid #ebeef5;
      height: auto;
      text-align: center;
    }
    p {
      margin-left: 30px;
    }
  }
}

.newFormStyle {
  ::v-deep .el-form-item--small.el-form-item {
    margin-bottom: 5px;
  }
  ::v-deep .el-input--small input {
    height: 30px;
    line-height: 30px;
  }
}
.generateSerialNoInfo {
  div {
    margin: 5px 10px;
  }
}
.printButton {
  text-align: right;
}
.btn-group {
  display: flex;
  justify-content: center;
}
.mt8 {
  margin-top: 8px;
}
</style>
